00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _vector_implementation_h_
00025 #define _vector_implementation_h_
00026
00027 #include <gridpack/parallel/distributed.hpp>
00028 #include <gridpack/utilities/uncopyable.hpp>
00029 #include <gridpack/utilities/complex.hpp>
00030 #include <gridpack/math/vector_interface.hpp>
00031 #include <gridpack/math/complex_operators.hpp>
00032
00033 namespace gridpack {
00034 namespace math {
00035
00036 class ImplementationVisitor;
00037 class ConstImplementationVisitor;
00038
00039
00040
00041
00042 template <typename T, typename I = int>
00043 class VectorImplementation
00044 : private utility::Uncopyable,
00045 public parallel::Distributed,
00046 public BaseVectorInterface<T, I>
00047 {
00048 public:
00049
00050 typedef typename BaseVectorInterface<T, I>::IdxType IdxType;
00051 typedef typename BaseVectorInterface<T, I>::TheType TheType;
00052
00053
00054 VectorImplementation(const parallel::Communicator& comm)
00055 : utility::Uncopyable(), parallel::Distributed(comm)
00056 {}
00057
00058
00059 ~VectorImplementation(void)
00060 {}
00061
00062
00063 void applyOperation(base_unary_function<TheType>& op)
00064 {
00065 this->p_applyOperation(op);
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 VectorImplementation *clone(void) const
00075 {
00076 return this->p_clone();
00077 }
00078
00079 protected:
00080
00081
00082 mutable std::vector<IdxType> p_rangeIdx;
00083
00084
00085 void p_buildRangeIdx(void) const
00086 {
00087 if (p_rangeIdx.empty()) {
00088 IdxType n(this->size());
00089 p_rangeIdx.reserve(n);
00090 std::copy(boost::counting_iterator<int>(0),
00091 boost::counting_iterator<int>(n),
00092 std::back_inserter(p_rangeIdx));
00093 }
00094 }
00095
00096
00097 virtual void p_applyOperation(base_unary_function<TheType>& op) = 0;
00098
00099
00100
00101 void p_setElementRange(const IdxType& lo, const IdxType& hi, TheType *x)
00102 {
00103 p_buildRangeIdx();
00104 IdxType n(hi - lo);
00105 this->p_setElements(n, &p_rangeIdx[lo], x);
00106 }
00107
00108
00109 void p_addElementRange(const IdxType& lo, const IdxType& hi, TheType *x)
00110 {
00111 p_buildRangeIdx();
00112 IdxType n(hi - lo);
00113 this->p_addElements(n, &p_rangeIdx[lo], x);
00114 }
00115
00116
00117 void p_getElementRange(const IdxType& lo, const IdxType& hi, TheType *x) const
00118 {
00119 p_buildRangeIdx();
00120 IdxType n(hi - lo);
00121 this->p_getElements(n, &p_rangeIdx[lo], x);
00122 }
00123
00124
00125 void p_real(void);
00126
00127
00128 void p_imaginary(void);
00129
00130
00131 virtual VectorImplementation *p_clone(void) const = 0;
00132
00133 };
00134
00135
00136 }
00137 }
00138
00139
00140
00141 #endif